package org.example;

import java.util.ArrayList;
import java.util.Arrays;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.FormHttpMessageConverter;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

public class Main {


    public static void main(String[] args) {

        RestTemplate restTemplate = new RestTemplate();
        restTemplate.getMessageConverters().add(new FormHttpMessageConverter());
        String fooResourceUrl = "http://baike.baidu.com/api/openapi/BaikeLemmaCardApi?scope=103&format=json&appid=379020&bk_key=%E5%85%B3%E9%94%AE%E5%AD%97&bk_length=600";
        MultiValueMap multiValueMap = new LinkedMultiValueMap();
        multiValueMap.put("bankCardId", new ArrayList(Arrays.asList(String.valueOf("1"))));
        HttpHeaders headers = new HttpHeaders();
        //设置请求媒体数据类型
        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
        //设置返回媒体数据类型
        headers.add("Accept", MediaType.APPLICATION_JSON_VALUE);
        HttpEntity<Object> formEntity = new HttpEntity<>(multiValueMap, headers);
        String response = restTemplate.postForObject(fooResourceUrl, formEntity, String.class);
        System.out.println(response);
    }
}